package com.ewhome.apartment.mvp.model;

import android.app.Application;

import com.ewhome.apartment.app.utils.AppUtils;
import com.ewhome.apartment.mvp.model.api.service.UserService;
import com.ewhome.apartment.mvp.model.entity.BaseData;
import com.ewhome.apartment.mvp.model.entity.req.Reqlogin;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;

import com.jess.arms.di.scope.ActivityScope;

import javax.inject.Inject;

import com.ewhome.apartment.mvp.contract.LoginActivityContract;

import io.reactivex.Observable;


@ActivityScope
public class LoginActivityModel extends BaseModel implements LoginActivityContract.Model {
    private Gson mGson;
    private Application mApplication;
    private UserService service;
    @Inject
    public LoginActivityModel(IRepositoryManager repositoryManager, Gson gson, Application application) {
        super(repositoryManager);
        this.mGson = gson;
        this.mApplication = application;
        this.service=repositoryManager.obtainRetrofitService(UserService.class);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mGson = null;
        this.mApplication = null;
    }

    @Override
    public Observable<BaseData> testLogin(String username, String password) {
        Reqlogin reqlogin=new Reqlogin(username,password);
        return service.request("http://192.168.0.221:8087/v1/login",AppUtils.String2RequestBody(mGson.toJson(reqlogin)));
    }
}